package com.shaobufan.museum.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shaobufan.museum.mapper.NoticeMapper;
import com.shaobufan.museum.pojo.entity.Notice;
import com.shaobufan.museum.pojo.request.notice.interior.NoticeAddRequest;
import com.shaobufan.museum.service.NoticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 17126
 * @description 针对表【notice(通知表)】的数据库操作Service实现
 * @createDate 2024-04-22 12:12:04
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
        implements NoticeService {
    @Resource
    NoticeMapper noticeMapper;

    /**
     * 添加通知
     *
     * @param noticeAddRequest 通知请求
     * @return Boolean
     */
    @Override
    public Boolean addNotice(NoticeAddRequest noticeAddRequest) {
        Notice notice = getNotice(noticeAddRequest);
        noticeMapper.insert(notice);
        return true;
    }

    @Override
    public List<Notice> searchNoticeByDepartId(Integer departId) {
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("depart_id", departId);

        return noticeMapper.selectList(queryWrapper);
    }

    public Notice getNotice(NoticeAddRequest noticeAddRequest) {
        Notice notice = new Notice();
        notice.setNoticeName(noticeAddRequest.getNoticeName());
        notice.setNoticeDetail(noticeAddRequest.getNoticeDetail());
        notice.setDepartId(noticeAddRequest.getDepartId());

        return notice;
    }
}




